package interview;

public class lc69 {
    public static void main(String[] args) {
        System.out.println(mySqrt(2147395599));
    }
    public static int mySqrt(int x) {
        long l = 0;
        long r = x;
        while (l <= r) {
            long mid = l + (r - l) / 2;
            if ((long)mid * mid < x) {
                l = mid + 1;
            } else if ((long)mid * mid > x){
                r = mid - 1;
            }
            else return (int) mid;
        }
        return (int)r;
    }
}
